'use strict';

const Service = require('egg').Service;

class StoreService extends Service {
    //查询此知识库是否存在
    async selectStore(title) {
        return await this.app.mysql.query('select * from storelist where title=?',[title])
    }
    async create(title,intro,uid,status,time){
        await this.app.mysql.query('insert into storelist (title,intro,uid,status,create_time) values (?,?,?,?,?)',[title,intro,uid,status,time])
    }
    //更新
    async update(title,intro,status,time,id){
        //title,intro,status,time,id
        await this.app.mysql.query('update storelist set title=?,intro=?,status=?,create_time=? where id=?',[title,intro,status,time,id])
    }
    //查询
    async index(uid){
        return await this.app.mysql.query('select * from storelist where uid=?',[uid])
    }

    //删除
    async delete(id){
        await this.app.mysql.query('delete from storelist where id=?',[id])
    }
    //删除该知识库下的所有文档
    async deleteWord(id){
        await this.app.mysql.query('delete from wordlist where s_id=?',[id])
    }
}

module.exports = StoreService;
